package com.woniu.controller;

import com.woniu.entity.Result;
import com.woniu.entity.dto.CourseAddDTO;
import com.woniu.entity.vo.CoursePublishVO;
import com.woniu.service.ICourseService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程表 前端控制器
 * </p>
 *
 * @author xiaotang
 * @since 2023-07-25
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private ICourseService courseService;

    /**
     * 添加课程
     * @param courseAddDTO
     * @return
     */
    @PostMapping
    public Result addCourse(@RequestBody CourseAddDTO courseAddDTO){
        Long id = courseService.saveCourse(courseAddDTO);
        return Result.ok(id);
    }



    @GetMapping("/{id}")
    public Result<CourseAddDTO> getCourseById(@PathVariable Long id){
        CourseAddDTO courseAddDTO = courseService.getCourseById(id);
        return Result.ok(courseAddDTO);
    }

    @PutMapping
    public Result updateCourse(@RequestBody CourseAddDTO courseAddDTO){
        Long id = courseService.updateCourse(courseAddDTO);
        return Result.ok(id);
    }

    @Operation(summary = "查询发布课程数据")
    @GetMapping("/publish/{courseId}")
    public Result<CoursePublishVO> getCoursePublishById(@PathVariable String courseId){
        CoursePublishVO coursePublishVo = courseService.getCoursePublishById(courseId);
        return Result.ok(coursePublishVo);
    }


}